package run.siyuan.jdk.高并发;

/**
 * {@code ClassName:} B
 * {@code Description:} TODO
 * {@code Author:} siyuan
 * {@code Date:} 2023/2/26 20:54
 */
public class B {

    static volatile int num = 1;

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (true) {
                if (num == 1) {
                    for (int i = 0; i < 9; i++) {
                        System.out.println("a" + i);
                    }
                    num = 2;
                    return;
                }
            }
        });
        Thread t2 = new Thread(() -> {
            while (true) {
                if (num == 2) {
                    for (int i = 0; i < 9; i++) {
                        System.out.println("b" + i);
                    }
                    num = 3;
                    return;
                }
            }
        });

        Thread t3 = new Thread(() -> {
            while (true) {
                if (num == 3) {
                    for (int i = 0; i < 9; i++) {
                        System.out.println("c" + i);
                    }
                    return;
                }
            }
        });
        t3.start();
        t2.start();
        t1.start();


    }

}
